<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    li{
      height: 50px;
      width: 200px;
      background-color: rgba(161, 190, 29, 0.657);
      margin-top: 10px;
    }
  </style>
</head>
<body>
  <div id="app">
    <input type="text" v-model="msg">
    {{ msg }}
    <hr>
    侦听对象
    <br>
    <input type="text" v-model="obj.a">
    {{ obj.a }}
    <br>
    <input type="text" v-model="obj.b">
    {{ obj.b }}
  </div>
  <script src="./vue.js"></script>
  <script>
    const vm = new Vue({
      el: "#app",
      data: {
        msg: '这是一个值',
        obj: {
          a: '这是a属性',
          b:'这是b属性'
        }
      },
      methods: {
       
      },
      watch: {
        msg(newVal, oldVal){
          console.log('侦听器触发了新值是'+ newVal);
        },
        /* obj(newVal){
          console.log('侦听对象成功了');
        } */
        // 直接侦听对象的某个属性
        /* 'obj.a'(newVal){
          console.log(newVal);
        }, */
        // 深度侦听对象
        obj: {
          handler(newVal){
            console.log('侦听器触发了');
            console.log(newVal);
          },
          deep: true // 深度监听
        }
      }
    })
  </script>
</body>
</html>